<#include "../common/layout/__mainlayout.html">
    <#include "../common/__pagination.html">
        <!--设置面包屑-->
        <#assign pageBreadCrumbs>
            <li class="active"><a href="#">专题管理</a></li>
            <li class="active">专题管理</li>
        </#assign>

        <#assign pageCss>
            <!-- page specific plugin styles -->
            <link rel="stylesheet" href="${ctx}/static/admin/assets/css/jquery-ui.custom.css"/>
            <link rel="stylesheet" href="${ctx}/static/admin/assets/css/datepicker.css"/>
            <link rel="stylesheet" href="${ctx}/static/admin/assets/css/daterangepicker.css"/>
            <link rel="stylesheet" href="${ctx}/static/admin/assets/css/zTreeStyle/zTreeStyle.css" type="text/css">

        </#assign>

        <#assign pageJavascript>
            <script src="${ctx}/static/admin/assets/js/jquery.validate.js"></script>
            <script src="${ctx}/static/admin/assets/js/jquery.validate.messages_zh.js"></script>
            <script src="${ctx}/static/admin/assets/js/ajaxfileupload.js"></script>

            <script type="text/javascript">

                function addTag(){
                    if ($("#softTagName") == null){
                        alert("标签名称不能为空");
                        return false;
                    }
                    if ($("#sortIndex") == null){
                        alert("标签顺序不能为空");
                        return false;
                    }
                    $("#softTagForm").submit();

                }

                $(document).ready(function(){

                    $("#softTagForm").validate({
                        errorElement: 'div',
                        errorClass: 'help-block',
                        focusInvalid: true,
                        highlight: function (e) {
                            $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
                        },
                        success: function (e) {
                            $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                            $(e).remove();
                        },
                        errorPlacement: function (error, element) {
                            if(element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
                                var controls = element.closest('div[class*="col-"]');
                                if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
                                else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                            }
                            else if(element.is('.select2')) {
                                error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                            }
                            else if(element.is('.chosen-select')) {
                                error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                            }
                            else error.insertAfter(element.parent());
                        },

                        submitHandler: function (form) {
                            $.ajax({
                                cache: true,
                                type: "POST",
                                url:"${ctx}/admin/softTag/saveTag.do",
                                data:$('#softTagForm').serialize(),// 你的formid
                                async: false,
                                error: function(request) {
                                    alert("Connection error");
                                },
                                success: function(data) {
                                    if(data.result == "success"){
                                        window.location="${refer!}";
                                    }else{
                                        alert(msg.messages);
                                    }
                                }
                            });
                        },
                        invalidHandler: function (form) {
                        }
                    })
                });
            </script>
        </#assign>

<@mainlayout pageBreadCrumbs=pageBreadCrumbs pageCss=pageCss pageJavascript=pageJavascript  currentMenu="softTagFlag-softTagListFlag">
        <form id="softTagForm" class="form-horizontal" action="${ctx}/admin/softTag/saveTag.do"  method="post">
                <div class="row">
                <div class="col-sm-12">
                    <div class="widget-box">
                        <div class="widget-header">
                            <h4 class="widget-title">编辑标签内容</h4>
                        </div>
                        <div class="widget-body">
                            <div class="widget-main">
                                <input type="hidden" name="tagId" id="tagId" class="col-xs-12 col-sm-4 required" value="${softTag.tagId!}"/>

                                <!--标签名称-->
                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="tagName">标签名称:</label>
                                    <div class="col-xs-12 col-sm-9">
                                        <div class="clearfix">
                                            <input type="text" name="tagName" id="tagName" class="col-xs-12 col-sm-8 required" value="${softTag.tagName!}"/>
                                        </div>
                                    </div>
                                </div>

                                <!--标签顺序-->
                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="sortIndex">标签顺序:</label>
                                    <div class="col-xs-12 col-sm-9">
                                        <div class="clearfix">
                                            <input type="number" name="sortIndex" id="sortIndex" class="col-xs-12 col-sm-8 required spinbox-input" value="${softTag.sortIndex!}" min="1" >
                                        </div>
                                    </div>
                                </div>

                                <!--状态-->
                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-3 no-padding-right" for="state">状态:</label>
                                    <div class="col-xs-12 col-sm-9">
                                        <div class="clearfix">
                                            <select class="input-medium" id="state" name="state">
                                                <option value="0" <#if !softTag.state?? ||(softTag.state?? && softTag.state = 0)>selected="selected"</#if>>显示</option>
                                                <option value="-1" <#if (softTag.state?? && softTag.state = -1)>selected="selected"</#if>>隐藏</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

                <div class="center">
                    <button type="button" onclick="addTag()" class="btn btn-sm btn-success"><i class="ace-icon fa fa-check"></i> 保存</button>
                    <button type="button" class="btn btn-sm" onclick="window.location='${ctx}/admin/softTag/softTagList.html';"><i class="ace-icon fa fa-times"></i> 取消</button>
                </div>
        </form>

        <div id="editModal" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                </div>
            </div>
        </div>

    </@mainlayout>
